package util;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.Arrays;

public class DifferencesCalculatorNEW {
	private final DoublePair[] expectedValuesOfWords = new DoublePair[10];

	private final Map realWords = new HashMap();

	private DoublePair[] differences = new DoublePair[512];

	private Translator tr = new Translator();

	public DifferencesCalculatorNEW() {
		expectedValuesOfWords[0] = new DoublePair("AAAAAAAAA", 44057.143);
		expectedValuesOfWords[1] = new DoublePair("AAAAAAAAG", 32957.282);
		expectedValuesOfWords[2] = new DoublePair("AAAAAAAGG", 26570.705);
		expectedValuesOfWords[3] = new DoublePair("AAAAAAGGG", 22856.771);
		expectedValuesOfWords[4] = new DoublePair("AAAAAGGGG", 20674.884);
		expectedValuesOfWords[5] = new DoublePair("AAAAGGGGG", 19456.202);
		expectedValuesOfWords[6] = new DoublePair("AAAGGGGGG", 18851.373);
		expectedValuesOfWords[7] = new DoublePair("AAGGGGGGG", 18698.597);
		expectedValuesOfWords[8] = new DoublePair("AGGGGGGGG", 18916.433);
		expectedValuesOfWords[9] = new DoublePair("GGGGGGGGG", 19512.806);
		/*
		expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 0);
		expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 0);
		expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 0);
		expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 0);
		expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 0);
		expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 0);
		expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 0);
		expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 0);
		*/
		//Aquifex aeolicus.ffn
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 4098.244);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 3402.067);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 3089.093);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 2987.749);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 3016.959);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 3131.672);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 3318.21);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 3563.9);
*/

			//Archaeoglobus fulgidus.ffn
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 6528.861);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 4999.279);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 4254.619);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 3912.65);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 3782.171);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 3781.616);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 3862.436);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 4005.526);
*/
			//Bacillus subtilis.ffn
/*
			expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 12725.679);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 9701.83);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 8069.504);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 7218.104);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 6810.266);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 6680.497);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 6743.487);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 6981.945);
*/
			//Bacteroides thetaiotaomicron.ffn 4
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 16473.726);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 14744.367);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 13966.454);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 13786.212);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 14013.926);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 14542.637);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 15332.368);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 16359.5);
*/

			//Chlamydia muridarum.ffn 5
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 3805.007);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 2939.286);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 2360.344);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 1959.394);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 1675.136);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 1466.14);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 1306.603);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 1186.665);
*/
			//Dehalococcoides ethenogenes.ffn 6
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 4447.093);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 3569.15);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 3029.922);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 2686.716);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 2466.712);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 2321.43);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 2233.193);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 2181.56);*/


			//Escherichia coli.ffn 7
			/*expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 18808.188);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 14275.195);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 11617.425);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 10000.631);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 9002.877);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 8369.218);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 7986.036);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 7779.592);*/


			//Fusobacterium nucleatum.ffn 8
			/*expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 5449.644);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 4269.552);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 3744.105);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 3606.802);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 3722.067);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 4025.165);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 4494.208);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 5126.753);*/


			//Gloeobacter violaceus.ffn 9
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 14397.347);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 11403.716);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 9365.883);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 7932.637);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 6888.959);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 6109.324);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 5519.321);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 5073.873);*/
			//Leptospira interrogans.ffn 10
			/*expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 8659.897);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 7312.957);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 6437.187);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 5858.3);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 5473.095);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 5218.8);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 5062.271);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 4968.213);*/

			//Nanoarchaeum equitans.ffn 11
			/*expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 1017.967);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 869.114);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 821.173);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 831.904);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 880.933);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 956.214);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 1054.885);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 1178.964);*/
			//Pirellula.ffn 12
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 15592.872);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 12765.374);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 10860.011);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 9534.575);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 8583.284);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 7897.005);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 7391.499);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 7024.366);
*/
			//Rubrobacter xylanophilus.ffn 13

		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 6694.378);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 5229.45);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 4367.79);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 3840.858);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 3503.828);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 3280.017);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 3138.046);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 3054.183);
*/
			//Sulfolobus acidocaldarius.ffn 14
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 7053.927);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 5108.663);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 4076.297);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 3531.647);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 3248.039);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 3122.247);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 3093.912);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 3139.424);*/
			//Thermotoga maritima.ffn 15
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 4630.241);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 3736.602);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 3244.31);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 2977.453);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 2837.962);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 2777.965);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 2769.327);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 2803.858);*/
			//Thermus thermophilus.ffn 16
			/*expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 7029.454);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 5336.329);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 4258.696);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 3533.719);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 3022.481);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 2643.419);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 2352.337);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 2122.421);*/
			//16_organisms
		/*	expectedValuesOfWords[0] = new DoublePair("AAAAAAA", 137396.991);
			expectedValuesOfWords[1] = new DoublePair("AAAAAAG", 109626.586);
			expectedValuesOfWords[2] = new DoublePair("AAAAAGG", 93538.839);
			expectedValuesOfWords[3] = new DoublePair("AAAAGGG", 84185.814);
			expectedValuesOfWords[4] = new DoublePair("AAAGGGG", 78925.657);
			expectedValuesOfWords[5] = new DoublePair("AAGGGGG", 76330.314);
			expectedValuesOfWords[6] = new DoublePair("AGGGGGG", 75646.108);
			expectedValuesOfWords[7] = new DoublePair("GGGGGGG", 76555.459);
*/

	}

	public void addSequenceUpdate(String sequence) {
		for (int j = 0; j < sequence.length() - 8; j++) {
			String subWord = sequence.substring(j, j + 9);
			add(subWord);
		}
	}

	private void add(String word) {
		if (realWords.containsKey(word)) {
			((DoublePair) realWords.get(word)).increment();
		} else {
			realWords.put(word, new DoublePair(word, 1));
		}
	}

	private int numberOfGs(String word) {
		int counter = 0;
		for (int i = 0; i < word.length(); i++) {
			if (word.substring(i, i + 1).equals("G"))
				counter++;
		}
		return counter;
	}

	public void calculateDifferences() {
		Set keys = realWords.keySet();
		Iterator iter = keys.iterator();
		int index = 0;
		while (iter.hasNext()) {
			DoublePair wordPair = (DoublePair) realWords.get(iter.next());
			//System.out.println(wordPair.getWord()+" "+wordPair.getNumber());
			String word = wordPair.getWord();
			int numOfGs = numberOfGs(word);
			wordPair.setNumber(wordPair.getNumber()
					- expectedValuesOfWords[numOfGs].getNumber());
			differences[index] = wordPair;
		//	System.out.println(differences[index].getWord()+" "+differences[index].getNumber());
			index++;
		}
	}

	public void newPrint(String fileName) throws IOException {
		PrintWriter writer=new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
		writer.println(",Sorted,Complementary");
		Arrays.sort(differences);

		for (int i = 0; i < differences.length; i++) {
			DoublePair temp = differences[i];
			DoublePair anti=findAntisense(temp.getWord());
			writer.println(temp.getWord() + "-" +anti.getWord()+","+ temp.getNumber()+ "," + anti.getNumber());
		}
		writer.close();
	}

	private void sort() {
		for (int i = 1; i < differences.length; i++) {
			DoublePair temp = differences[i];
			int j = i - 1;
			while (j >= 0 && differences[j].getNumber() > temp.getNumber()) {
				differences[j + 1] = differences[j];
				j--;
			}
			differences[j + 1] = temp;
		}
	}

	private DoublePair findRandom(Set differences) {
		DoublePair toReturn = null;
		int temp = (int) (Math.random() * differences.size());
		Iterator iter = differences.iterator();
		int index = 0;
		while (iter.hasNext() && differences.size() != 0) {
			if (index == temp) {
				toReturn = (DoublePair) iter.next();
			} else {
				iter.next();
			}
			index++;
		}
		differences.remove(toReturn);
		if (toReturn == null)
			System.out.println("Huston - we have another problem here!!!");
		return toReturn;

	}

	private Set createDifferencesSet() {
		Set toReturn = new HashSet();
		for (int i = 0; i < differences.length; i++) {
			toReturn.add(differences[i]);
		}
		return toReturn;
	}

	public void printNumberOfPositive() {
		int posCounter = 0;
		int negCounter = 0;
		for (int i = 0; i < differences.length; i++) {
			if (differences[i].getNumber() > 0) {
				posCounter++;
			}
			if (differences[i].getNumber() < 0) {
				negCounter++;
			}

		}
		System.out.println("positive=" + posCounter);
		System.out.println("negative=" + negCounter);
	}

	private Vector sortedRandomlyPaired() {
		DoublePair[] sortedSense = new DoublePair[differences.length / 2];
		DoublePair[] sortedAntisense = new DoublePair[differences.length / 2];
		int s = 0;
		Set differencesSet = createDifferencesSet();
		for (int i = 0; i < differences.length / 2; i++) {

			sortedSense[s] = findRandom(differencesSet);

			sortedAntisense[s] = findRandom(differencesSet);

			s++;
		}

		for (int a = 1; a < sortedSense.length; a++) {
			DoublePair temp = sortedSense[a];
			DoublePair tempAnti = sortedAntisense[a];
			double max = Math.max(tempAnti.getNumber(), temp.getNumber());

			int b = a - 1;
			double tempMax = Math.max(sortedSense[b].getNumber(),
					sortedAntisense[b].getNumber());
			while ((b >= 0) && (tempMax > max)) {
				sortedSense[b + 1] = sortedSense[b];
				sortedAntisense[b + 1] = sortedAntisense[b];
				b--;
				if (b >= 0)
					tempMax = Math.max(sortedSense[b].getNumber(),
							sortedAntisense[b].getNumber());
			}
			sortedSense[b + 1] = temp;
			sortedAntisense[b + 1] = tempAnti;
		}

		for (int j = 0; j < sortedSense.length; j++) {
			DoublePair temp = sortedSense[j];
			DoublePair tempAnti = sortedAntisense[j];
			if (temp.getNumber() < tempAnti.getNumber()) {
				sortedSense[j] = sortedAntisense[j];
				sortedAntisense[j] = temp;
			}

		}

		DoublePair[] newToReturn = new DoublePair[sortedSense.length];
		DoublePair[] newAntiDiffs = new DoublePair[sortedAntisense.length];
		int s1 = sortedSense.length - 1;
		for (int a = 0; a < sortedSense.length; a++) {
			newToReturn[s1] = sortedSense[a];
			newAntiDiffs[s1] = sortedAntisense[a];
			s1--;
		}

		Vector vec = new Vector();
		vec.add(newToReturn);
		vec.add(newAntiDiffs);
		return vec;
	}

	private Vector sortedComplementary() {
		DoublePair[] sortedSense = new DoublePair[differences.length / 2];
		DoublePair[] sortedAntisense = new DoublePair[differences.length / 2];
		int s = 0;

		for (int i = 0; i < differences.length; i++) {
			//System.out.println(differences.length);
			String wordOfInterst = differences[i].getWord();
			if ((!contains(sortedAntisense, wordOfInterst))
					&& (!contains(sortedSense, wordOfInterst))) {
				sortedSense[s] = differences[i];
				sortedAntisense[s] = findAntisense(differences[i].getWord());
				s++;
			}

		}
		// /////////////////////////
		for (int a = 1; a < sortedSense.length; a++) {
			DoublePair temp = sortedSense[a];
			DoublePair tempAnti = sortedAntisense[a];
			double max = Math.max(tempAnti.getNumber(), temp.getNumber());

			int b = a - 1;
			double tempMax = Math.max(sortedSense[b].getNumber(),
					sortedAntisense[b].getNumber());
			while ((b >= 0) && (tempMax > max)) {
				sortedSense[b + 1] = sortedSense[b];
				sortedAntisense[b + 1] = sortedAntisense[b];
				b--;
				if (b >= 0)
					tempMax = Math.max(sortedSense[b].getNumber(),
							sortedAntisense[b].getNumber());
			}
			sortedSense[b + 1] = temp;
			sortedAntisense[b + 1] = tempAnti;
		}

		for (int j = 0; j < sortedSense.length; j++) {
			DoublePair temp = sortedSense[j];
			DoublePair tempAnti = sortedAntisense[j];
			if (temp.getNumber() < tempAnti.getNumber()) {
				sortedSense[j] = sortedAntisense[j];
				sortedAntisense[j] = temp;
			}

		}

		DoublePair[] newToReturn = new DoublePair[sortedSense.length];
		DoublePair[] newAntiDiffs = new DoublePair[sortedAntisense.length];
		int s1 = sortedSense.length - 1;
		for (int a = 0; a < sortedSense.length; a++) {
			newToReturn[s1] = sortedSense[a];
			newAntiDiffs[s1] = sortedAntisense[a];
			s1--;
		}

		// /////////////////////////
		Vector vec = new Vector();
		vec.add(newToReturn);
		vec.add(newAntiDiffs);
		return vec;
	}

	private boolean contains(DoublePair[] pairs, String word) {
		for (int i = 0; i < pairs.length; i++) {
			if ((pairs[i] != null) && (pairs[i].getWord().equals(word)))
				return true;
		}
		return false;
	}

	private DoublePair findAntisense(String word) {
		for (int i = 0; i < differences.length; i++) {
			if (differences[i].getWord().equals(tr.complementAndReverse(word))) {
				return differences[i];
			}
		}
		System.out.println("We got a problem Hustone...");
		return null;
	}

	public void printSorted() {
		sort();
		for (int i = 0; i < differences.length; i++) {
			System.out.println(differences[i]);
		}
	}

	public void printVector() {
		Vector v = sortedComplementary();
		DoublePair[] a = (DoublePair[]) v.elementAt(0);
		DoublePair[] b = (DoublePair[]) v.elementAt(1);
		int counter = 0;
		double aNumber;
		double bNumber;
		for (int i = 0; i < a.length; i++) {
			aNumber = a[i].getNumber();
			bNumber = b[i].getNumber();
			/*System.out.println(i + "  " + aNumber + "  "
					+ bNumber);*/
			System.out.println(a[i].getWord().toLowerCase() + "-"
					+ b[i].getWord().toLowerCase() + "  " + aNumber + "  "
					+ bNumber);
			if ((aNumber > 0 && bNumber > 0) || (aNumber < 0 && bNumber < 0)
					|| (aNumber == 0 && bNumber == 0))
				counter++;
		}
		System.out.println("Good pairs num = " + counter);
	}

	public void printVectorOfShuffledPairs() {
		Vector v = sortedRandomlyPaired();
		DoublePair[] a = (DoublePair[]) v.elementAt(0);
		DoublePair[] b = (DoublePair[]) v.elementAt(1);
		int counter = 0;
		double aNumber;
		double bNumber;
		for (int i = 0; i < a.length; i++) {
			aNumber = a[i].getNumber();
			bNumber = b[i].getNumber();
			/*System.out.println(a[i].getWord().toLowerCase() + " "
					+ b[i].getWord().toLowerCase() + " , " + aNumber + " , "
					+ bNumber);*/
			System.out.println(i + "  " + aNumber + "  " + bNumber);

			if ((aNumber > 0 && bNumber > 0) || (aNumber < 0 && bNumber < 0)
					|| (aNumber == 0 && bNumber == 0))
				counter++;
		}
		System.out.println("Good pairs num = " + counter);
	}

	public void printAverageNumberOfGoodPairsOver1000() {

		double sum = 0;
		for (int index = 0; index < 10000; index++) {
			Vector v = sortedRandomlyPaired();
			System.out.println(index);
			DoublePair[] a = (DoublePair[]) v.elementAt(0);
			DoublePair[] b = (DoublePair[]) v.elementAt(1);
			int counter = 0;
			double aNumber;
			double bNumber;
			for (int i = 0; i < a.length; i++) {
				aNumber = a[i].getNumber();
				bNumber = b[i].getNumber();
				if ((aNumber > 0 && bNumber > 0)
						|| (aNumber < 0 && bNumber < 0)
						|| (aNumber == 0 && bNumber == 0))
					counter++;
			}
			sum = sum + counter;
		}
		System.out.println("Good pairs num = " + sum / 10000.0);
	}

}
